package http_servlet_response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Creared with IntelliJ IDEA.
 * Description:
 * User:yxd
 * Date:2022-05-31
 * Time:22:36
 */
@WebServlet("/testRefresh")
public class testRedirectServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //网上搜索 SimpleDateFormat 类的用法, 让页面上能够显示格式化的时间. 例如 2022-01-19 12:00:00
        Date currentTime = new Date();
//        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        resp.setHeader("Refresh","1");
        resp.setContentType("text/html;charset=utf8");
        resp.getWriter().write("当前时间:" + simpleDateFormat1.format(currentTime));
    }
}
